package com.example.order.mybatis;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.internal.DefaultCommentGenerator;

/**
 * 网上找的 自定义备注生成器, 把表的字段备注拿过来放到类属性的备注上
 *                       
 * @Filename: MyCommentGenerator.java
 * @Version: 1.0
 * @Author: peter朱硕磊
 * @Email: 455474281@qq.com
 *
 */
public class MyCommentGenerator extends DefaultCommentGenerator {

    /**  * 为字段添加注释   */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        //$NON-NLS-1$
        field.addJavaDocLine("/**");
        String remarks = introspectedColumn.getRemarks();
        field.addJavaDocLine(remarks);
        addJavadocTag(field, false);
        //$NON-NLS-1$
        field.addJavaDocLine(" */");
    }

    /**  * 给getter方法加注释  */
    @Override
    public void addGetterComment(Method method, IntrospectedTable introspectedTable,
                                 IntrospectedColumn introspectedColumn) {

        StringBuilder sb = new StringBuilder();
        //$NON-NLS-1$
        method.addJavaDocLine("/**");
        sb.append(introspectedColumn.getRemarks());
        method.addJavaDocLine(sb.toString());
        addJavadocTag(method, false);
        //$NON-NLS-1$
        method.addJavaDocLine(" */");

    }

    /**  * 给setter方法加注释  */
    @Override
    public void addSetterComment(Method method, IntrospectedTable introspectedTable,
                                 IntrospectedColumn introspectedColumn) {
        //$NON-NLS-1$
        StringBuilder sb = new StringBuilder();
        method.addJavaDocLine("/**");
        sb.append(introspectedColumn.getRemarks());
        method.addJavaDocLine(sb.toString());
        addJavadocTag(method, false);
        //$NON-NLS-1$
        method.addJavaDocLine(" */");
    }

}
